<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'regist.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" type="text/css" href="/CSS/regist.css">
<script type="text/javascript">
	function tname() {
		var name = document.getElementById("userName").value;
		var nullname = document.getElementById("nullname");
		if (name == null || name == "") {
			nullname.innerHTML = "用户名不能为空！";
			return false;
		} else if (name.length<2||name.length> = 20) {
			nullname.innerHTML = "用户名长度为2--20个字符长度！";
			return false;
		} else {
			nullname.innerHTML = "";
			return true;
		}

	}

	function ppwd() {
		var pwd = document.getElementById("password").value;
		var nullpwd = document.getElementById("nullpwd");
		if (pwd == null || pwd == "") {
			nullpwd.innerHTML = "密码不能为空！";
			return false;
		} else {
			nullpwd.innerHTML = "";
			return true;
		}
	}

	function ttpwd() {
		var pwd = document.getElementById("password").value;
		var tpwd = document.getElementById("tpwd").value;
		var nulltpwd = document.getElementById("nulltpwd");
		alert(pwd);
		alert(tpwd);
		if (tpwd == null || tpwd == "") {
			nulltpwd.innerHTML = "确认密码不能为空！！！";
			return false;
		} else if (tpwd != pwd) {
			nulltpwd.innerHTML = "两次密码输入不一致";
			return false;
		} else {
			nulltpwd.innerHTML = "";
			return true;
		}
	}

	function eemail() {
		var eamil = document.getElementById("email").value;
		var nullemail = document.getElementById("nullemail");
		// var reg=/^[a-zA-Z0-9_-]+@(126|163|qq|sohu|sina+\.)+(com|cn|net|org)$/  
		var reg = /^[a-zA-Z0-9_-]+@(126.com|163.com|qq.com|sohu.com|sina.com|hotmail.com|gmail.com|yahoo.cn)$/;
		if (eamil == null || eamil == "") {
			nullemail.innerHTML = "Email地址不能为空";
			return false;
		} else if (!reg.test(eamil)) {
			nullemail.innerHTML = "请输入正确的Email地址！！";
			return false;
		} else {
			nullemail.innerHTML = "";
			return true;
		}
	}

	function ttel() {
		var tel = document.getElementById("tel").value;
		var nulltel = document.getElementById("nulltel")
		var reg = /^[1]{1}[3,5,8]{2}[0-9]{8}$/
		if (tel == null || tel == "") {
			nulltel.innerHTML = "手机号不能为空！！！";
			return false;
		} else if (tel.length != 11 || !reg.test(tel)) {
			nulltel.innerHTML = "请正确填写手机号";
			return false;
		} else {
			nulltel.innerHTML = "";
			return true;
		}
	}
	function reg() {
		if (tname() && ppwd() && ttpwd() && eemail() && ttel()) {
			document.forms[0].submit();
			return true;
		} else {
			return false;
		}
	}
</script>

</head>
<!-- ^[A-Za-z0-9]+$ 26字母和数字 -->
<body>

	<center>
		<fieldset style="width: 500px;">
			<legend>注册</legend>
			<form action="regUser" method="post">
				<table>
					<tr>
						<td>用户名</td>
						<td><input type="text" name="user.userName" class="w"
							id="userName" onblur="tname()" /></td>
						<td><div id="nullname"></div></td>
					</tr>

					<tr>
						<td>密码</td>
						<td><input type="password" name="user.password" class="w"
							id="password" onblur="ppwd()" /></td>
						<td><div id="nullpwd"></div></td>
					</tr>

					<tr>
						<td>确认密码</td>
						<td><input type="password" name="tpwd" class="w" id="tpwd"
							onblur="ttpwd()" /></td>
						<td><div id="nulltpwd"></div></td>
					</tr>

					<tr>
						<td>性别</td>
						<td><input type="radio" value="男" checked="checked"
							name="user.sex" />男 <input type="radio" value="女" name="user.sex" />女
						</td>
						<td></td>
					</tr>
					<tr>
						<td>Email</td>
						<td><input type="text" name="user.email" class="w" id="email"
							onblur="eemail()" /></td>
						<td>
							<div id="nullemail"></div>
						</td>
					</tr>

					<tr>
						<td>手机</td>
						<td><input type="text" name="user.tel" class="w" id="tel"
							onblur="ttel()" /></td>
						<td><div id="nulltel"></div></td>
					</tr>

					<tr>
						<td></td>
						<td><input type="button" value="注册" onclick="reg()" /><input
							type="reset" value="重填" /></td>
						<td></td>
					</tr>
				</table>
			</form>
		</fieldset>
	</center>
</body>
</html>
